<?php
/**
 * AccountAgentTradeLogsList
 *
 * @package Akimimi front
 * @author by M.Wang
 */

require_once '../app/views/BaseView.php';
class AccountAgentTradeLogsListView extends BaseView {

    public $logs;
    protected $tradetype;
    public $pager;
    public $tradetypes;
    public $formdata = array(
        'page' => 1,
        'sn' => '',
        'createdd' => '',
        'createdu' => ''
    );
    public $action = '/trade/supplementlogs/';
    public $detailAction = '/trade/tradeloginfo/';

    public function setTradeType($int_tradetype){
        $this->tradetype = $int_tradetype;
        if( $this->tradetype > 1 )
            $this->action = '/trade/withdrawlogs/';
    }

    public function getPage(){
        $arr_navsetting = array(
            array('url'=>'/userinfo/index', 'text'=>MYAKIMIMITXT),
            array('text'=>constant('AATLTRADETYPELIST'.$this->tradetype))
        );
        $this->setPageTitle(constant('AATLTRADETYPELIST'.$this->tradetype));
        $this->addCSS('tradelog.css');
        $this->addCSS('myaccountleftnav.css');
        $this->addCSS('jquery.ui.css');
        $this->addJS('lib/ui.core.js',true);
        $this->addJS('lib/jquery-ui-datepicker.js',true);
        $str_js = "
            <script type='text/javascript'>
            $(document).ready(function() {
                $('#log_createdd').datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'yy-mm-dd'
                });
                $('#log_createdu').datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'yy-mm-dd'
                });
            });
            </script>";
        $this->setHeadExtends($str_js);
        $header = '';
        require_once '../app/views/MyAccoutLeftNavView.php';
        $myAccountLeftNavView = new MyAccountLeftNav();
        $str_result = $header
                    . $this->getNavigation($arr_navsetting)
                    . "<div id='mymimi_body'>"
                    . $myAccountLeftNavView->getMyAccountLeftNav()
                    . $this->getContent()
                    . '</div>';
        return $this->getHtmlPage($str_result);
    }

    public function getContent(){
        return "<div id='mymimi_right'><div class='right_bj'></div>"
               . "<div id='coupons_list'>"
               . $this->getSearchBlock()
               . $this->getGrid()
               . '</div></div>';
    }

    public function getGrid(){
        $str_result = "<div class='coupons_border' style='margin-top:18px;'>%s</div>";
        $str_table = $this->getTableHead() . $this->getTableBody() . $this->getTableFooter();
        return sprintf($str_result, $str_table);
    }

    protected function getTableHead(){
        return "<div class='coupons_row'><ul>"
               . "<li class='style_1'><b>" . ($this->tradetype > 1 ? AATLSNTXT : AATLORDERIDTXT) . '</b></li>'
               . "<li class='style_2'><b>" . constant( 'ATT' . $this->tradetype . 'COSTNTXT' ) . '</b></li>'
               . "<li class='style_3'><b>" . AATLCOSTTYPETXT . '</b></li>'
               . "<li class='style_4'><b>" . AATLSTATUSTXT . '</b></li>'
               . "<li class='style_4'><b>" . constant( 'ATT' . $this->tradetype . 'PAYTIMENTXT' ) . '</b></li>'
               . "<li class='style_3'><b>" . constant( 'ATT' . $this->tradetype . 'PAYTYPENTXT' ) . '</b></li>'
               . "<li class='style_5'><b>" . AATLACTIONTXT . '</b></li>'
               . '</ul></div>';
    }

    protected function getTableBody(){
        if (empty($this->logs))
            return '';
        $str_result = '';
        foreach ($this->logs as $arr_log) {
            $str_result.= "<div class='coupons_row'><ul>"
                        . "<li class='style_1'><a href='{$this->detailAction}{$arr_log['id']}'>" . ($this->tradetype > 1 ? $arr_log['sn'] : $arr_log['trade_num']) . '</a></li>'
                        . "<li class='style_2'>" . $arr_log['trade_sum'] . '</li>'
                        . "<li class='style_3'>" . ($this->tradetype>1 ? AgentAccount::getAgentAccountWithdrawType( $arr_log['withdraw_type'] ) : AgentAccount::getAgentAccountSupplementType( $arr_log['supplement_type'])) . '</li>'
                        . "<li class='style_4'>" . AgentAccount::getAgentAccountTradeLogStatus( $arr_log['status'] ) . '</li>'
                        . "<li class='style_4'>" . $arr_log['created'] . '</li>'
                        . "<li class='style_3'>" . ($arr_log['about_type']<1 ? constant( 'ATT' . $arr_log['trade_type'] . 'COSTTYPEVALUE0') : ($arr_log['about_type']<2 ? constant( 'ATT' . $arr_log['trade_type'] . 'COSTTYPEVALUE1' ) : constant( 'ATT' . $arr_log['trade_type'] . 'COSTTYPEVALUE2' ))) . '</li>'
                        . "<li class='style_5'><a href='{$this->detailAction}{$arr_log['id']}'>" . AATLDETAILLINKE . '</a></li>'
                        . '</ul></div>';
        }
        return $str_result;
    }

    protected function getTableFooter(){
        if (empty($this->logs))
            return '';
        return "<div class='coupons_row_1'><div class='p2_page'>" . $this->getPager() . '</div></div>';
    }

    protected function getPager(){
        $pager = new Pager('searchTradeLogsForm','pageNumber',true);
        return $pager->paginate($this->formdata['page'], $this->pager['countrows'], $this->action );
    }

    protected function getSearchBlock(){
        $str_result = "<form id='searchTradeLogsForm' method='post' action='{$this->action}'>"
               . "<input type='hidden' id='pageNumber' name='page' value='{$this->formdata['page']}' />"
               . "<div class='order_row'><ul>";
        if( $this->tradetype > 1 ){
            $str_result.= "<li style='width: 20px; text-align: center;'>" . AATLSNNTXT . '</li>'
               . "<li style='width:100px;'><input style='width:100px;' type='text' name='sn' value='{$this->formdata['sn']}' /></li>"
               . "<li style='width: 100px; text-align: center;'>" . constant( 'ATT' . $this->tradetype . 'PAYTIMETXT' ) . '</li>'
               . "<li style='width:90px;'><input id='log_createdd' style='width:90px;' type='text' name='createdd' value='{$this->formdata['createdd']}' /></li>"
               . "<li style='width: 10px; text-align: center;'>" . '&nbsp;-&nbsp;' . '</li>'
               . "<li style='width:90px;'><input id='log_createdu' style='width:90px;' type='text' name='createdu' value='{$this->formdata['createdu']}' /></li>"
               . "<li style='width: 60px; text-align: center;'>" . constant( 'ATT' . $this->tradetype . 'PAYTYPETXT' ) . '</li>'
               . "<li style='width:110px;'>" . $this->getTradeType($this->formdata['payment_type']) . '</li>'
               . "<li style='margin-left:20px;'><input type='submit' value=' " . OLSSUBMITBTN . " ' /></li>";
        }else{
            $str_result.= "<li style='width:90px; text-align: center;'>" . AATLORDERIDNTXT . '</li>'
               . "<li style='width:100px;'><input style='width:100px;' type='text' name='trade_num' value='{$this->formdata['trade_num']}' /></li>"
               . "<li style='width: 60px; text-align: center;'>" . constant( 'ATT' . $this->tradetype . 'PAYTIMETXT' ) . '</li>'
               . "<li style='width:80px;'><input id='log_createdd' style='width:80px;' type='text' name='createdd' value='{$this->formdata['createdd']}' /></li>"
               . "<li style='width: 10px; text-align: center;'>" . '&nbsp;-&nbsp;' . '</li>'
               . "<li style='width:80px;'><input id='log_createdu' style='width:80px;' type='text' name='createdu' value='{$this->formdata['createdu']}' /></li>"
               . "<li style='width: 60px; text-align: center;'>" . constant( 'ATT' . $this->tradetype . 'PAYTYPETXT' ) . '</li>'
               . "<li style='width:110px;'>" . $this->getTradeType($this->formdata['payment_type']) . '</li>'
               . "<li style='margin-left:20px;'><input type='submit' value=' " . OLSSUBMITBTN . " ' /></li>";
        }
        $str_result.= '</ul></div></form>';
        return $str_result;
    }

    protected function getTradeType($int_type){
        $str_result = "<option value=''>" . AATLSELECTTXT . '</option>';
        foreach ($this->tradetypes as $int_key => $str_value) {
            if( $int_key < 1 )
                continue;
            $str_result.= "<option value='{$int_key}' " . ($int_type == $int_key ? "selected='selected'" : '') . ">{$str_value}</option>";
        }
        return "<select name='payment_type'>{$str_result}</select>";
    }

}
?>